import 'package:lepig/common/config/theme.dart';
import 'package:lepig/model/ProductModel.dart';
import 'package:lepig/model/SelectProductTypeModel.dart';
import 'package:lepig/pages/home/otherPage/OtherPage.dart';
import 'package:lepig/request/HttpSelectProductType.dart';
import 'package:lepig/request/HttpSelectProducts.dart';
import 'package:lepig/request/HttpSelectShopPlatform.dart';
import 'package:lepig/widget/SearchView.dart';
import 'package:flutter/material.dart';
import 'package:lepig/mock/productTypes.dart';
import 'package:flutter/services.dart';

import 'firstPage/FirstPage.dart';

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _Home();
  }

}
class _Home extends State<Home> {
  List<SelectProductTypeModel> list = new List<SelectProductTypeModel>();

  initState(){

    getSelectTypeProduct();


  }

  //获取分类
  getSelectTypeProduct(){
    HttpSelectProductType(this.context,1).then((value){
      setState(() {
        this.list=value;
      });
    });
  }


  List<Tab> createBar() {
    return list.map((SelectProductTypeModel productType) {
      return new Tab(
        text: productType.name,
      );
    }).toList();
  }



  @override
  Widget build(BuildContext context) {
    return  new DefaultTabController(
      length: list.length,
      child: new Scaffold(
        appBar: new AppBar(
          elevation: 0, //阴影的高度
          title: SearchView(),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.thumb_up),
              onPressed: () {},
            ),
            IconButton(icon: Icon(Icons.share), onPressed: () {}),
          ],
        ),
        body:new Column(
          children: <Widget>[
            new Container(
              color: curColor,
              child:  new Flex(
                direction: Axis.horizontal,
                children: <Widget>[
                  Expanded(
                    flex:1,
                    child: new TabBar(
                      indicatorWeight: 2,
                      indicatorPadding: EdgeInsets.only(bottom: 10.0),
                      indicatorColor:Colors.white,
                      isScrollable: true,
                      indicatorSize:TabBarIndicatorSize.tab,
                      tabs: [
                        ...createBar(),
                      ],
                    ),
                  ),
                  new Container(
                    width: 50,
                    child: new InkWell(
                      child: new Container(
                        child: new IconButton(icon: Icon(Icons.more_horiz), onPressed: (){}),
                      ),
                    ),
                  )
                ],
              ),
            ),
            Expanded(
              child: new TabBarView(
                children: list.map((SelectProductTypeModel productType) {
                  if(productType.id==1){
                    return new FirstPage();
                  }else{
                    return new OtherPage(list: productType.child,productTypeModel: productType,);
                  }
                }).toList(),
              ),
            )
          ],
        ),
      ),
    );
  }
}


